package cn.tedu.egmvc3.controller;

import cn.tedu.egmvc3.mapper.EmpMapper;
import cn.tedu.egmvc3.pojo.EmpVO;
import cn.tedu.egmvc3.pojo.entity.Emp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/emp/")
public class EmpController {
    @Autowired(required = false)
    private EmpMapper empMapper;

    /**
     * 添加员工
     * @param emp
     * @return 添加成功
     */
    @RequestMapping("insert")
    public String insert(Emp emp){
        empMapper.insertEmp(emp);
        return "添加成功";
    }

    @RequestMapping("select")
    public List<EmpVO> select(){
        List<EmpVO> list = empMapper.selectEmp();
        return list;
    }

    @RequestMapping("update")
    public String update(Emp emp){
        empMapper.updateEmp(emp);
        return "修改成功";
    }

    @RequestMapping("delete")
    public String delete(int id){
        empMapper.deleteEmp(id);
        return "删除成功";
    }
}
